//
//  MyUnderTableViewCell.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/2/4.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//

#import "MyUnderTableViewCell.h"
#import "BkMessageOrderView.h"
@interface MyUnderTableViewCell()

@property (nonatomic, strong) UIView *bacView;
@property (nonatomic, strong) UILabel *userNameLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UIView *septorLine;
@property (nonatomic,strong) UILabel *bkNameLabel;
@property (nonatomic,strong) UILabel *moneyLabel;
@property (nonatomic,strong) UILabel *sevendaysLabel;
@property (nonatomic,strong) UILabel *amountLabel;
@property (nonatomic,strong) UIView *bottomLine;
@property (nonatomic,strong) UIButton *confirmDoneBtn;
@property (nonatomic,strong) UILabel *totalAmountLabel;
@property (nonatomic,strong) UILabel *totalShouyiLabel;
@property (nonatomic,strong) UIImageView *headerImgView;
@property (nonatomic,strong) UIButton *cancellBtn;

@property (nonatomic,strong) NSArray *messageArray;
@property (nonatomic,strong) NSMutableArray *uiMessageArray;
@end

@implementation MyUnderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self viewConfig];
    }
    return self;
}
-(void)viewConfig
{   self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = kMainBgColor;
    [self.contentView addSubview:self.bacView];
    [self.bacView addSubview:self.userNameLabel];
    [self.bacView addSubview:self.dateLabel];
    [self.bacView addSubview:self.septorLine];

     [self.bacView addSubview:self.bottomLine];
    [self.bacView addSubview:self.totalAmountLabel];
    [self.bacView addSubview:self.totalShouyiLabel];
    
   
    
}
-(UIView *)bacView{
    if (!_bacView) {
        _bacView = [[UIView alloc]initWithFrame:CGRectMake(TSScaleW(15), TSScaleW(10), TSScaleW(345), TSScaleW(168))];
        _bacView.backgroundColor = kWhiteColor;
        [_bacView setCornerRadius:TSScaleW(10)];
    }
    return _bacView;
}
-(UILabel *)userNameLabel{
    if (!_userNameLabel) {
        _userNameLabel = [TSWLTools allocLabel:@"订单编号：20201525452" font:systemFont(TSScaleW(12)) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(15), TSScaleW(17), _bacView.width - TSScaleW(15)*2, TSScaleW(12)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _userNameLabel;
}
-(UILabel *)dateLabel{
    if (!_dateLabel) {
        _dateLabel = [TSWLTools allocLabel:@"已完成" font:systemFont(TSScaleW(13)) textColor:kGreenColor frame:CGRectMake(TSScaleW(15), TSScaleW(17), _bacView.width - TSScaleW(15)*2, TSScaleW(13)) textAlignment:(NSTextAlignmentRight)];
    }
    return _dateLabel;
}
-(UIView *)septorLine
{
    if (!_septorLine) {
        _septorLine = [[UIView alloc]initWithFrame:CGRectMake(0, TSScaleW(14) + _userNameLabel.bottom, _userNameLabel.width, .5)];
        _septorLine.backgroundColor = kMainLineColor;
    }
    return _septorLine;
}
-(UIImageView *)headerImgView{
    if (!_headerImgView) {
        _headerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(TSScaleW(15), TSScaleW(15) + _septorLine.bottom, TSScaleW(47), TSScaleW(63))];
        _headerImgView.backgroundColor = kGrayTxtColor;

    }
    return _headerImgView;
}
-(UILabel *)bkNameLabel{
    if (!_bkNameLabel) {
        _bkNameLabel = [TSWLTools allocLabel:@"初中数学运算大法" font:systemFont(TSScaleW(14)) textColor:kMainTxtColor frame:CGRectMake(_headerImgView.right + TSScaleW(10),  _septorLine.bottom + TSScaleW(18), TSScaleW(210), TSScaleW(14)) textAlignment:(NSTextAlignmentLeft)];
        //_bkNameLabel.numberOfLines = 0;
    }
    return _bkNameLabel;
}
-(UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel = [TSWLTools allocLabel:@"￥999.00" font:systemFont(TSScaleW(12)) textColor:kMainTxtColor frame:CGRectMake(_headerImgView.right + TSScaleW(10), _bkNameLabel.top, TSScaleW(260), TSScaleW(15)) textAlignment:(NSTextAlignmentRight)];
        NSString *string = _moneyLabel.text;
        NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string];
        [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(1,  string.length - 4)];
        _moneyLabel.attributedText = atts;
    }
    return _moneyLabel;
}
-(UILabel *)sevendaysLabel{
    if (!_sevendaysLabel) {
        _sevendaysLabel = [TSWLTools allocLabel:@"7天无理由退换" font:systemFont(10) textColor:UIColorFromRGB(0xD95F35) frame:CGRectMake(_bkNameLabel.left, TSScaleW(9) + _bkNameLabel.bottom, TSScaleW(80), TSScaleW(15)) textAlignment:(NSTextAlignmentCenter)];
        _sevendaysLabel.backgroundColor = UIColorFromRGB(0xFFF1F1);
        _sevendaysLabel.cornerRadius = _sevendaysLabel.height/2.f;
        
    }
    return _sevendaysLabel;
}
-(UILabel *)amountLabel{
    if (!_amountLabel) {
        _amountLabel = [TSWLTools allocLabel:@"x1" font:systemFont(12) textColor:kGrayTxtColor frame:CGRectMake(_moneyLabel.left, TSScaleW(37) + _moneyLabel.bottom, _moneyLabel.width , TSScaleW(12)) textAlignment:(NSTextAlignmentRight)];
    }
    return _amountLabel;
}
-(UIView *)bottomLine
{
    if (!_bottomLine) {
        _bottomLine = [[UIView alloc]initWithFrame:CGRectMake(_headerImgView.left, TSScaleW(13) + _headerImgView.bottom, TSScaleW(318), .5)];
        _bottomLine.backgroundColor = kMainLineColor;
       }
       return _bottomLine;
}
-(UILabel *)totalAmountLabel
{
    if (!_totalAmountLabel) {
        _totalAmountLabel = [TSWLTools allocLabel:@"共1件商品" font:systemFont(12) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(15), TSScaleW(14) + _bottomLine.bottom, _bacView.width - TSScaleW(15)*2, TSScaleW(12)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _totalAmountLabel;
}
-(UILabel *)totalShouyiLabel
{
    if (!_totalShouyiLabel) {
        _totalShouyiLabel = [TSWLTools allocLabel:@"合计：￥100.00" font:systemFont(12) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(15), TSScaleW(14) + _bottomLine.bottom, _bacView.width - TSScaleW(15)*2, TSScaleW(12)) textAlignment:(NSTextAlignmentRight)];
        NSString *string = _totalShouyiLabel.text;
        NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string];
        [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(4,  string.length - 7)];
        _totalShouyiLabel.attributedText = atts;
    }
    return _totalShouyiLabel;
}

-(void)setMessageArray:(NSArray *)messageArray{
    _messageArray = messageArray;
    for (UIView *v  in self.uiMessageArray) {
        [v removeFromSuperview];
    }
    [self.uiMessageArray removeAllObjects];
    CGFloat top = self.septorLine.bottom;
    for (int i = 0; i <self.messageArray.count; i ++) {
        NSDictionary *dataDic = self.messageArray[i];
        BkMessageOrderView *messageView = [[BkMessageOrderView alloc]init];
        messageView.top = top;
        top += messageView.height;
        _bottomLine.top = messageView.bottom;
        messageView.dataDic = dataDic;
        [self.bacView addSubview:messageView];
        [self.uiMessageArray addObject:messageView];
    }
    
    self.totalAmountLabel.top = TSScaleW(14) + _bottomLine.bottom;
    self.totalShouyiLabel.top = self.totalAmountLabel.top;
    _bacView.height = TSScaleW(52) + _bottomLine.bottom;
   
    
    
   // self.totalAmountLabel.text = [NSString stringWithFormat:@"@"共1件商品""]
    
    
}
-(NSMutableArray *)uiMessageArray{
    if (!_uiMessageArray) {
        _uiMessageArray = [NSMutableArray array];
    }
    return _uiMessageArray;
}
-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.messageArray = _dataDic[@"ordertailList"];
    _userNameLabel.text = [NSString stringWithFormat:@"订单编号：%@",_dataDic[@"ordernum"]];
    _dateLabel.text = _dataDic[@"adtime"];
    NSString *  goodsprice = _dataDic[@"goodsprice"];
    NSString *profitmoney = _dataDic[@"profitmoney"];
    _totalAmountLabel.text = [NSString stringWithFormat:@"合计：￥%.2f",goodsprice.doubleValue];
    _totalShouyiLabel.text = [NSString stringWithFormat:@"收益：￥%.2f",profitmoney.doubleValue];
    NSString *string = _totalShouyiLabel.text;
    NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string];
    [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(4,  string.length - 7)];
    _totalShouyiLabel.attributedText = atts;
     string = _totalAmountLabel.text;
    NSMutableAttributedString *atts1 = [[NSMutableAttributedString alloc] initWithString:string];
    [atts1 setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(4,  string.length - 7)];
    _totalAmountLabel.attributedText = atts1;
}

@end
